package httptool;

import android.content.Context;
import android.util.Log;

import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;

/**
 * Created by Administrator on 2016/6/5/005.
 */
public class takeUrlResource {
    static String content;
    private static takeUrlResource mInstance = null;

    public static takeUrlResource newInstance() {
        if (mInstance == null) {
            mInstance = new takeUrlResource();
        }
        return mInstance;
    }

    /**
     * Get 获取Json数据
     */
    public static void getJson(final Context context, final String url,
                               Response.Listener<String> success) {
        RequestQueue queue = Volley.newRequestQueue(context);
        StringRequest request = new StringRequest(Request.Method.GET,

                url, success, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                Log.e("error", error.toString());
            }
        }
        );
        if (0 == CommonUtil.isNetworkAvailable(context)) {
            ShowDialog.showToast(context,"无网络，请检查网络连接！");
        } else {
            queue.add(request);
        }
    }

}
